package com.gdip.controller;


import com.gdip.common.dtos.ResponseResult;
import com.gdip.dto.ProblemDTO;
import com.gdip.dto.ReplyDTO;
import com.gdip.po.ProblemPo;
import com.gdip.service.ProblemService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    ProblemService problemService;

    @PostMapping("/submit")
    public ResponseResult addProblem(@RequestBody ProblemDTO problemDTO,HttpSession session){
        Integer userId = (Integer) session.getAttribute("userId");

        return problemService.addProblem(problemDTO,userId);
    }

    @GetMapping("/listHistory")
    public ResponseResult listProblem(HttpSession session){
        Integer userId = (Integer) session.getAttribute("userId");
        return problemService.listProblem(userId);
    }


    @PostMapping("/replyProblem")
    public ResponseResult replyProblem(@RequestBody ReplyDTO replyDTO, HttpSession session){

        Integer userId = (Integer) session.getAttribute("userId");
        System.out.println("用户id"+userId);

        return problemService.replyProblem(replyDTO,userId);
    }


    @GetMapping("/listTProblems")
    public ResponseResult listTeacherProblems(HttpSession session){
        Integer userId = (Integer) session.getAttribute("userId");

        return problemService.listTeacherProblems(userId);
    }
    @GetMapping("/getAllProblems")
    public ResponseResult getAllProblems(@RequestParam(required = false) String title) {
        return problemService.findProblemsByTitleAndCreateTime(title);
    }

    @GetMapping("/getClasses")
    public ResponseResult getClasses(){
        return problemService.getClasses();
    }

    @GetMapping("/getTypes")
    public ResponseResult getTypes(){
        return problemService.getTypes();
    }


//    @GetMapping("/getHistory")
//    public ResponseResult getHistory(HttpSession session){
//        Integer userId = (Integer) session.getAttribute("userId");
//
//        return problemService.getHistory(userId);
//    }

    @GetMapping("/getProblemReply")
    public ResponseResult getProblemReply(HttpSession session){
        Integer userId = (Integer) session.getAttribute("userId");

        return problemService.getProblemReply(userId);
    }

    @GetMapping("/listReply")
    public ResponseResult listReply(HttpSession session){
        Integer userId = (Integer) session.getAttribute("userId");

        return problemService.listReply(userId);
    }

    @PostMapping("/rollback")
    public ResponseResult rollback(@RequestBody ProblemDTO problemDTO){
        Integer id = problemDTO.getId();

        return problemService.rollback(id);
    }

    @GetMapping("/getBackProblems")
    public ResponseResult getBackProblems(){
        return problemService.getBackProblems();
    }

    @PostMapping("/updateClass")
    public ResponseResult updateClass(@RequestBody ProblemDTO problemDTO){
        return problemService.updateClass(problemDTO);
    }




}
